<template>
      <div class="swiper-container" id="mySwiper"  ref="mySwiper1">
          <div class="swiper-wrapper">
            <div
              class="swiper-slide"
              v-for="(car, index) in list"
              :key="car.id"
            >
              <img :src="car.imgUrl" />
            </div>
          </div>
          <!-- 如果需要分页器 -->
          <div class="swiper-pagination"></div>

          <!-- 如果需要导航按钮 -->
          <div class="swiper-button-prev"></div>
          <div class="swiper-button-next"></div>
        </div>
</template>

<script>
import Swiper from "swiper";
export default {
  name:'Carousel',
  props:['list'],
    watch: {
    //监听bannerList的数据变化,因为这条数据发生过变化---由空数组变为数组有四个元素
    list: {
      //这里是不管数据有无变化都会做一次监视
      immediate:true,
      handler(newValue, oldValue) {
        //现在咱们通过watch监听bannerlist的数值变化
        //当前的函数执行保证数组有了,v-for有没有把结构渲染完毕不保证
        this.$nextTick(() => {
          console.log('nexttick的调用')
          //当你执行回调的时候  保证服务器数据回来了.v-for执行完毕了
          var mySwiper = new Swiper(this.$refs.mySwiper1, {
            loop: true, // 循环模式选项
            // 如果需要分页器
            pagination: {
              el: ".swiper-pagination",
            },

            // 如果需要前进后退按钮
            navigation: {
              nextEl: ".swiper-button-next",
              prevEl: ".swiper-button-prev",
            },

            // // 如果需要滚动条
            // scrollbar: {
            //   el: '.swiper-scrollbar',
            // },
          });
        });
      },
    },
  },

}
</script>

<style>

</style>